﻿using Ledict.ConditionExtract.Base;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Ledict.ConditionExtract
{
    public partial class ActionWindow : BaseForm
    {
        public ActionWindow()
        {
            InitializeComponent();
        }
        string labelText = string.Empty;
        string titleNew = string.Empty;
        public ActionWindow(string text,string title)
        {
            InitializeComponent();
            labelText = text;
            titleNew = title;
        }
        Timer timer1=new Timer();
        int counter = 10;
        private void ActionWindow_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(labelText))
            {
                textBox1.Text = labelText;
                textBox1.ForeColor = Color.Red;
                this.Text = titleNew;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (counter == 10)
            {
                button1.Text = "确定（10S)";
                button1.Enabled = false;
                timer1.Enabled = true;
                timer1.Interval = 1000;
                timer1.Tick += Timer1_Tick;
                timer1.Start();
            }
            else if(counter==0)
            {
                this.Close();
                DialogResult = DialogResult.OK;
            }
        }

        private void Timer1_Tick(object sender, EventArgs e)
        {
            counter--;
            if (counter == 0)
            {
                button1.Enabled = true;
                timer1.Enabled = false;
                timer1.Stop();
                button1.Text = "确定";
                return;
            }
            else
            {
                button1.Text = "确定（"+counter+"S）";
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
            DialogResult = DialogResult.Cancel;
        }

        private void ActionWindow_FormClosing(object sender, FormClosingEventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }
    }
}
